﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.IO;
using System.Transactions;
using System.Data;
using System.Diagnostics.Contracts;
namespace Data_Converter
{
    /// <summary>
    /// This program converts raw text files in the format that google uses for it's transit info
    /// and converts it to a database format for easy searching
    /// </summary>
    static class Program
    {      
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            TextWriter outW = System.Console.Out;
            TextWriter errW = System.Console.Error;
            Contract.Assume(outW != null);
            Contract.Assume(errW != null);
            
            using (System.Data.SQLite.SQLiteConnection dbconn = new System.Data.SQLite.SQLiteConnection("data source=\"C:\\Users\\jake\\ProjectsRoot\\Mobile Bus Schedule\\db\\ottawa.db\""))
            {
                dbconn.Open();
                using (ScheduleInfo octranspo = new ScheduleInfo(dbconn))
                {
                    GoogleTransit.Converter converter = new GoogleTransit.Converter();
                    octranspo.SubmitChanges();
                    String startupPath = Application.StartupPath;
                    Contract.Assume(startupPath != null);
                    DirectoryInfo rawDataFolder = new DirectoryInfo(Path.Combine(Application.StartupPath, "raw"));
                    if (rawDataFolder.Exists)
                    {
                        converter.Convert(octranspo, rawDataFolder);
                        outW.WriteLine("About to commit changes");
                        outW.WriteLine("All done");
                    }
                    else
                    {
                        errW.WriteLine("Could not find data directory");
                    }                    
                }
            }
        }
    }
}
